#include <stdio.h>
#include <stdlib.h>
#include "arrayQueue.h"

ArrayQueue *createArrayQueue() {
    ArrayQueue *arrayQueue = (ArrayQueue *) malloc(sizeof(ArrayQueue));
    arrayQueue->front = arrayQueue->rear = 0;			// 队列为空

    return arrayQueue;
}

void releaseArrayQueue(ArrayQueue *arrayQueue) {
    if (arrayQueue) {
        free(arrayQueue);
    }
}

int enArrayQueue(ArrayQueue *queue, Element e) {
    if (queue->flags == 1) {
        printf("the queue is full\n");
        return -1;
    }

    queue->rear = (queue->rear + 1) % MAXQueueSize;
    queue->data[queue->rear] = e;

    if ((queue->rear + 1) % MAXQueueSize == queue->front) {
        queue->flags = 1; // 队列已满
    }
    return 0;
}

int deArrayQueue(ArrayQueue *queue, Element *e) {

    if (queue->flags == 0) {
        printf("the queue is empty\n");
        return -1;
    }

    queue->front = (queue->front + 1) % MAXQueueSize;
    *e = queue->data[queue->front];

    if (queue->rear == queue->front) {
        queue->flags = 0; // 队列已空
    }
    return 0;
}



















